//
//  DynamicFooterView.m
//  nonghubao
//
//  Created by 王 文彬 on 13-3-10.
//  Copyright (c) 2013年 Chongqing Nonghubao Co., Ltd. All rights reserved.
//

#import "DynamicFooterView.h"
#import "Config.h"

@implementation DynamicFooterView

- (id)initWithFrame:(CGRect)frame  forStyle:(FooterViewStyle)style
{
    self = [super initWithFrame:frame];
    if (self) {
        
        //根据样式，设定图标和数字的大小
        float iconWidth = 16.5f;
        float iconHeight = 15.0f;
        float labelWidth = 26.5f;
        float labelHeight = 15.0f;
        if (style == FooterViewStyleMultiBig) {
            iconWidth = 18.0f;
            iconHeight = 17.0f;
            labelWidth = 30.0f;
            labelHeight = 17.0f;
        }
        
        
        //评论icon
        _commentedIcon = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"com_icon_005"]];
        _commentedIcon.backgroundColor = [UIColor clearColor];
        _commentedIcon.frame = CGRectMake(10, 2, iconWidth, iconHeight);
        [self addSubview:_commentedIcon];
        
        //评论计数
        _commentedCountLabel = [[UILabel alloc] initWithFrame:CGRectMake(30, 2, labelWidth, labelHeight)];
        _commentedCountLabel.backgroundColor = [UIColor clearColor];
        _commentedCountLabel.textColor = _SYS_COLOR_002;
        [self addSubview:_commentedCountLabel];
        
        
        //商品动态和推荐动态才有以下图片和计数
        if (style == FooterViewStyleMultiBig || style == FooterViewStyleMultiSmall) {
            
            //售出icon
            _soldIcon = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"com_icon_006"]];
            _soldIcon.backgroundColor = [UIColor clearColor];
            _soldIcon.frame = CGRectMake(60, 2, iconWidth, iconHeight);
            [self addSubview:_soldIcon];
            
            //售出计数
            _soldCountLabel = [[UILabel alloc] initWithFrame:CGRectMake(80, 2, labelWidth, labelHeight)];
            _soldCountLabel.backgroundColor = [UIColor clearColor];
            _soldCountLabel.textColor = _SYS_COLOR_002;
            [self addSubview:_soldCountLabel];
            
            
            //赞icon
            _recommendedIcon = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"com_icon_007"]];
            _recommendedIcon.backgroundColor = [UIColor clearColor];
            _recommendedIcon.frame = CGRectMake(110, 2, iconWidth, iconHeight);
            [self addSubview:_recommendedIcon];
            
            //赞计数
            _recommendedCountLabel = [[UILabel alloc] initWithFrame:CGRectMake(130, 2, labelWidth, labelHeight)];
            _recommendedCountLabel.backgroundColor = [UIColor clearColor];
            _recommendedCountLabel.textColor = _SYS_COLOR_002;
            [self addSubview:_recommendedCountLabel];

        }
    }
    return self;
}


// 设定3个元素值
- (void)setNumbersWithCommented:(NSInteger)commented andSold:(NSInteger)sold andRecommended:(NSInteger)recommended;
{
    _commentedCountLabel.text    = [NSString stringWithFormat:@"%i", commented];
    _soldCountLabel.text         = [NSString stringWithFormat:@"%i", sold];
    _recommendedCountLabel.text  = [NSString stringWithFormat:@"%i", recommended];
}


// 改变外观
- (void)setFrame:(CGRect)frame forStyle:(FooterViewStyle)style
{
    //根据样式，设定图标和数字的大小
    float iconWidth = 16.5f;
    float iconHeight = 15.0f;
    float labelWidth = 26.5f;
    float labelHeight = 15.0f;
    if (style == FooterViewStyleMultiBig) {
        iconWidth = 18.0f;
        iconHeight = 17.0f;
        labelWidth = 30.0f;
        labelHeight = 17.0f;
    }
    
    self.frame = frame;
    
    //评论icon
    _commentedIcon.frame = CGRectMake(10, 2, iconWidth, iconHeight);
    _soldIcon.frame = CGRectMake(60, 2, iconWidth, iconHeight);
    _recommendedIcon.frame = CGRectMake(110, 2, iconWidth, iconHeight);
}

@end
